/***************************************************************************
 *   Copyright (C) 2007 by Ernesto Barragan*
 *   ernestus@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <QtGui>
#include "weekicker.h"
#include "taskviewicons.h"

#ifdef Q_WS_X11
#include <X11/Xlib.h>
#include <QX11Info>
#endif

WeeKicker::WeeKicker( QWidget *parent )
	:QWidget( parent )
{
    setupUi(this);
    vboxLayout1->removeWidget(listWidget_runningTasks);
    delete listWidget_runningTasks ;
    listWidget_runningTasks = dynamic_cast<QListWidget*>(new TaskViewIcons( widget_runningTasks )) ;
    listWidget_runningTasks->setViewMode(QListView::IconMode);
    vboxLayout1->addWidget(listWidget_runningTasks);
#ifdef Q_WS_X11
    setWindowFlags( Qt::Desktop ) ; //crash w/o X
    setWindowFlags( Qt::X11BypassWindowManagerHint ) ;
#endif
    setWindowFlags( Qt::FramelessWindowHint ) ;
}

WeeKicker::~WeeKicker()
{
}

/*!
    \fn WeeKicker::getRunningApps()
 */
void WeeKicker::getRunningApps()
{
#ifdef Q_WS_X11
    ///@todo complete me!

    Window root_dummy, parent_dummy ; //useful when debugging
    Window* children ;
    uint numberOfChildren ;
    char *windowname ;
    //XWindowAttributes attr;

    if( XQueryTree( QX11Info::display(), QX11Info::appRootWindow(), &root_dummy, &parent_dummy, &children, &numberOfChildren) == 0 )
    {
        ///@todo failed!
    }

    for(unsigned int currentChildNumber=0; currentChildNumber < numberOfChildren; currentChildNumber++)
    {
        Window currentWindow = children[currentChildNumber] ;
        /*
            if( currentWindow == qapp::tb->winId() )
                continue;
            XGetWindowAttributes(QX11Info::display(), currentWindow, &attr);
        */
        if (0 != XFetchName( QX11Info::display(), currentWindow, &windowname) )
        {
            XFree( windowname ) ;
        }
    }
    //XMapRaised (dpy, window);
    //XSync (dpy, False);
    //XSync(QX11Info::display(), FALSE);
    //XGetWMName();
    //XmbTextPropertyToTextList();
#endif

#ifdef Q_WS_QWS
	
#endif
}
